package com.ruoyi.project.jiaqin.supplycollect.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.supplycollect.domain.JiaqinSupplyCollect;
import com.ruoyi.project.jiaqin.supplycollect.service.IJiaqinSupplyCollectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应收藏Controller
 * 
 * @author admin
 * @date 2021-01-05
 */
@Controller
@RequestMapping("/jiaqin/supplycollect")
public class JiaqinSupplyCollectController extends BaseController
{
    private String prefix = "jiaqin/supplycollect";

    @Autowired
    private IJiaqinSupplyCollectService jiaqinSupplyCollectService;

    @RequiresPermissions("jiaqin:supplycollect:view")
    @GetMapping()
    public String supplycollect()
    {
        return prefix + "/supplycollect";
    }

    /**
     * 查询供应收藏列表
     */
    @RequiresPermissions("jiaqin:supplycollect:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        startPage();
        List<JiaqinSupplyCollect> list = jiaqinSupplyCollectService.selectJiaqinSupplyCollectList(jiaqinSupplyCollect);
        return getDataTable(list);
    }

    /**
     * 导出供应收藏列表
     */
    @RequiresPermissions("jiaqin:supplycollect:export")
    @Log(title = "供应收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        List<JiaqinSupplyCollect> list = jiaqinSupplyCollectService.selectJiaqinSupplyCollectList(jiaqinSupplyCollect);
        ExcelUtil<JiaqinSupplyCollect> util = new ExcelUtil<JiaqinSupplyCollect>(JiaqinSupplyCollect.class);
        return util.exportExcel(list, "supplycollect");
    }

    /**
     * 新增供应收藏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应收藏
     */
    @RequiresPermissions("jiaqin:supplycollect:add")
    @Log(title = "供应收藏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        return toAjax(jiaqinSupplyCollectService.insertJiaqinSupplyCollect(jiaqinSupplyCollect));
    }

    /**
     * 修改供应收藏
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinSupplyCollect jiaqinSupplyCollect = jiaqinSupplyCollectService.selectJiaqinSupplyCollectById(id);
        mmap.put("jiaqinSupplyCollect", jiaqinSupplyCollect);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应收藏
     */
    @RequiresPermissions("jiaqin:supplycollect:edit")
    @Log(title = "供应收藏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        return toAjax(jiaqinSupplyCollectService.updateJiaqinSupplyCollect(jiaqinSupplyCollect));
    }

    /**
     * 删除供应收藏
     */
    @RequiresPermissions("jiaqin:supplycollect:remove")
    @Log(title = "供应收藏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinSupplyCollectService.deleteJiaqinSupplyCollectByIds(ids));
    }
}
